
package horde.utils;

import java.io.File;
import java.net.URL;
import java.util.Scanner;
import javax.swing.ImageIcon;

/**
 * @author Andres Picazo and Arturo Mazon
 */
public class RawLoader {

//    private static final String rawStandardImagePath = "/horde/standard/resources/graphics/raw/";
    private static final String rawStandardImagePath = "/horde/internalResources/raw/";
    public static final String blizzardSplash = "blizzard-splash.jpg";
    public static final String hordeSplash = "horde-splash.png";
    public static final String hordeIcon = "horde-18x18.png";

    /**
     * Gets an image contained in the directory stored in the variable "rawStandardImagePath"
     * @param imageName Name for the image
     * @return ImageIcon containing the image, null if there's any error
     */
    public ImageIcon getStandardImage(String imageName) {
        URL location = getClass().getResource(rawStandardImagePath + imageName);
        return new ImageIcon(location);
    }

    /**
     * Gets an image contained in the directory stored in the location given in the parameter "path"
     * @param path Location for the image (not including the image name)
     * @param imageName Name of the image
     * @return Processed image
     */
    public ImageIcon getStandardImage(String path, String imageName) {
        URL location = getClass().getResource(path + imageName);
        return new ImageIcon(location);
    }

    public static ImageIcon getRawImage (String imageName) {
        RawLoader rl = new RawLoader();
        return rl.getStandardImage(imageName);
    }


    public static ImageIcon getRawImage (String path, String imageName) {
        RawLoader rl = new RawLoader();
        return rl.getStandardImage(path, imageName);
    }

    /**
     * @param path
     * @return
     */
    public Scanner getScannerForPath(String path) {
        URL location = getClass().getResource(path);
        String processedPath = location.getPath();
        /* There are problems with spaces in the path, replaced with %20, this has to be undone */
        processedPath = processedPath.replaceAll("%20", " ");
        File f = new File(processedPath);
        try {
            return new Scanner(f);
        } catch (Exception e) {
            System.err.println ("ERROR(Loader): Can't create scanner for: " + processedPath);
            // hc.send (new exp (["Causa", "Acceso no valido"],["¿Se puede acceder al fichero?", f.canRead().toString()]));
            return null;
        }
    }

    public String getSystemPath (String path) {
        URL location = getClass().getResource(path);
        return location.getPath().replaceAll("%20", " ");
    }
}
